package org.mcb.zebra.portal.servlet;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mcb.zebra.portal.manager.PortalManager;

@SuppressWarnings({"serial","unchecked"})
public class ZebPortalServlet extends HttpServlet {
	RequestHandler handler; 
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		String className = config.getInitParameter(PortalManager.INIT_PARAM_HANDLE);
		try {
			Class clazz = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
			handler = (RequestHandler) clazz.newInstance();
		} catch (ClassNotFoundException e) {
			throw new ServletException(e);
		} catch (InstantiationException e) {
			throw new ServletException(e);
		} catch (IllegalAccessException e) {
			throw new ServletException(e);
		}
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		handler.handelRequest(req, resp, getServletContext());
	}
}
